TODO: add comments to this file to indicate what these functions actually do.