updated searching function