Revised Code to correct Error with Search