Did refactor to remove duplicate code, changed text_entry to put latest entry at the top of the history, and added comments.