finish searching function