Added some binary search magic