refactor code to move routes at the beginning