#822 - unit tests, fix issues found during testing