updated search function for better use with button