refactored routing to make code more testable