Avoid overflow and underflow.