better edge case handling