Refactor the router