Refactors response logic