Rewritten bin_search