Changed logical structure of handling requests to the controller to be
more readable (maintained original logic)