refactoring routing logic