router code refactoring