Separated out the routing code