Added check for headers sent in header function