Refactored the request handler