finishing touches and added comments to explain all code