Use Perl's PREINIT: blocks to ensure variables are declared before to code

Also includes some general consistency cleanup.
Don't use C99 initialization syntax