Refactors respond function.