improve error handling; found improved parseResponseHeaders function