Testing, sweet, sweet corrected testing

Also, refactoring.

Take a look at the individual commit diffs for the full story.