refactor the request-handler logic