added some comments to help code reading