Refactor to enable execution from command line