Refactoring for better error handling, so that all responses are handled by the response class