Minor fixes and unit tests