Refactored code for method chaining and removed Servlet