Refactor and clean up, support ModuleDefs, minimal tests