Massive coding style cleanup

Enforce some coding style rules all over the existing code, simplify code where possible.