Increase test coverage

This adds 32 new tests and brings test coverage up to 100%.

I also did some cleanup along the way too.

r?