refactor the router handler