misc fixes, unit tests