Refactored reponse parsing to be easier to read