Simplifying search algorithm