[Reviewer Graeme] Issue838

Graeme

Can you review my fix to #838.  The fix to the problem as reported was trivial, but I also spotted another case of the same bug so fixed that as well.  The UTs all run cleanly, but it isn't a case we can currently test with a UT so I haven't added any test cases.  Also, since the bug+fix is so obvious, I haven't worried about reproducing it live.

Mike