Fix buggy overflow/underflow management