refactored the router to make it easier to extend