added comments to text processing logic