fix finished and finalized search algorithm. Working well