Fix division by zero in extreme cases