WIP: abstracting out while loops from parseHeaders