added some comments to help with understanding