fix "headers already sent" messages in output