Fix 'headers already sent' issue