Fix a bug with edge cases.