added comments to each line to show understanding