[Reviewer: Matt] UT robustness

Hi Matt - please can you review? This makes the UTs more reliable, in particular, it makes the one test that reliably failed under Valgrind pass. Details in commit log.

Thanks.

--KW 8-)