ref #4028 - add unit-test, various fixes