added comments to better explain code