Refactor routes code.