added comments to help people understand and for me to remember how its done