Refactoring route logic