chain of responsibility pattern def application(envstart_response)authorization_header env["http_authorization"header_array authorization_header split(encoded_string header_array[ decoded_string base decode(encoded_stringdecode('utf- 'usernamepassword decoded_string split(":"user user get_verified_user(usernamepasswordstart_response(' ok'[('content-type''text/html')]path env["path_info"split("/"if "goodbyein pathresponse "goodbye {}!format(user nameelseresponse "hello {}!format(user namereturn [response encode('utf- ') ' sure your code sense is making lot of noise right now the application function is clearly doing three different things right now it starts out getting the user object thenit decides what endpoint the client is requesting and composes the relevant message based on that path lastlyit returns the encoded message to the client who made the request whenever more functionality is required between the initial request from the user and the actual responsethe application function becomes more complex in shortyour code is bound to become mess if you continue down this path we want each function to ideally do one and only one thing the chain of responsibility pattern the idea that every piece of code does one thing and only one thing is called the single responsibility principlewhich is another handy guideline when you are working on writing better code