Modernize format, fix bugs.

THere are still some function definitions missing ...