added some comments to improve readability