binary search completed, with so many if statements