Refactor parsing the headers into key value pairs