fixed hidden infinite loop possiblity in text_retrieve