refactored parseHeaders and fixed up tests