binary search refactor