More refactoring; improvements to modularity