generalizing get_text_list helper
better comment for the algorithm