refactored some of the routing code