Added comments to describe what happens where.