Finish unit tests, fix a few tiny issues along the way