Various improvements. See description

Reintroduced internal variables, as static.
Improved formatting
bugfixes
added compiler option to control whether it writes stuff to the screen