fix issue #5, plus some new work on test code