Refactored the routing-related functionality