Rebuilt search function