The points should been noted:

  1. The middle position is not (right - left) / 2, it must be left + ((right - left) / 2).