added comments to make clear what the functions do