Improvements for handling edge cases.