I'd be happier if you included some of the test-cases I dreamed up while pointing out ways the original code wouldn't do what was intended.  Then we might be sure we've caught those corner cases ...