optimized version, eliminated unnecessary calls to bin_search