updated code to handle headers