Fixed binary search algorithm bug and tests