added comments to help make code clearer