refactor routes and handlers