Added comments to make it easier to follow