Add code comments

Comments to the code for a better understanding.