Refined searching algorithm