refactored method to prepare response