moved some more out of main file. page generation is a mess!!
ripped out most of script-guard and trace-php-error