Improved edge case handling