refactoring of response handling.