Updating for use as an imported module in addition to cli.