Bug fix for bug #1092 and bug #696

Add fix, and a unit test, for bug #1092 ... and also fix bug #696