debugged and added comments to code