Now works for both cgi-bin and mod_perl
Seems to be working now...
Tidy and remove debug code