Added all the comments for explanation