added additional comments and explanations