bug fix for "headers already sent"