added code to handle header and response messages