Cleaning, safety etc.

A lot less changes than the diff is indicating. Knocked everything
<80px; fiddled with the comments; changed the order of the functions.
etc.