Added code and comments to functions