Fix some bugs that occurred on test machines

There were some pretty nasty bugs that became apparent when I consulted
my tester. In the process of fixing those bugs, the code saw some needed
improvement as well. Within my small test base, everything seems to be
working perfectly.