added additional comments to make code clearer