Fixed search function

added some condition check