Added comments to explain what is going on.