refactoring of response.js - get rid of if else hell