Refactor main classes into modules