Added some comments to explain the code a bit more