added comments to the text processing logic