added some code comments to make stuff more comprehensible