Updating code with comments

Explained the code functioning with appropriate comments