Fix overflow and underflow