Refactor router to use functions instead of on router.