fix 'headers already sent' errors