Removed debugging code and added comments to functions