Added some more comments to better explain the code.