Parsing data from response and cleaned up the code