added some comments to make things clearer