improved code for new text search