Fixed insertion of headers at the end