Formatted code and added additional comments.