debugged and added comments to the code