Refactored router to remove duplication