Improved the routing logic