Added comments to reflect the operation of each function.