refactored reusable code into initResponse() method