More refactoring and general fixes, including of module types Signed-off-by: David Shah <davey1576@gmail.com>