Fixing 'header already sent' errors