Refactoring to modules