Massive refactoring into modules