Moved code out of CLI.