updated code with comments.