Improved on previous edits.

Class-change code is clearer and more versatile now, added extensive
comments to the code, and generally just cleaned up a bit.