fix overflow corner cases