Major changes to preprocessor

The preprocessor has been overhauled, but is now working very well and
is more robust. Almost all of the templates had to be rewritten. They
still need to be checked.