Improve handling of corner cases