bug in setting middle for binary search