modify searchbar code to be more robust