Added some comments to explain the code