Cherry picking change to master
Merging changes from upstream and adding some comments