added improved search function