Updated code with some comments.