Updated to add logic to functions
Added comments to functions