Updated search function to retain this variable