added comments to some tricky parts