Add missed test case. Update code to correctly handle that case, plus
others as uncovered by further testing.