Refactor the route matching in the dispatcher