added comments to clarify purpose of code