Lots of small refactors

A lot of noise from the whitespace changes, add ?w=1 to the url to see without whitespace changes.
None of this should change code operation