refinement, move request processing logic to handler, and improve code