Improved handling of some edge cases