Unit tests, miscellaneous tweaks