Improved the routing code