Refactoring routes code out of rest