clean up code (remove cruft; modularize; consistentize; apply conventions; 'use strict'; resolve warnings)

@rpl: Now that 2.0 is (almost) out the door, I'm doing some code cleanup in preparation for the next development cycle. So this branch contains a number of changes. And I'm concerned that they might conflict with changes you're making that are almost ready to merge.

So if you have any of those, then let me know when those changes will be ready! If it's soon enough, I'll hold back this cleanup to enable your merges to happen first (and then resolve the conflicts when merging your changes into this branch).

If your changes are not going to be ready for a while, though, then I'll merge these changes in first, and you'll have to resolve the merge conflicts.

Don't worry about making me resolve the conflicts. I'm happy to do so if your changes are almost ready! Just let me know. :-)