refactors routing and extracts some modules