Still further fixes to handling of corner cases.
Some tests to help out weed the bugs