Introduced ModuleManager and copied code with as little changes as possible into ModuleManager.