Refactored some code, wrote some tests.

Been doing a lot of "chores" for the code base. A lot of code (written by me) that I needed to clean up. As the code base gets bigger, this takes up at least 30-40% of my time on a weekly basis.