Some fixes to cgi headers sent error