Improved seach function