added additional comments throughout
added additional comments to make code clearer