added error checking for header retrieval