added some comments to make the code more explicit.