Refactoring the code to avoid duplication of the responses control