Fix crash as recommended by Ben Wilhelm, add a test to verify the fix and add a test from David Amnon.