Moved the bulk of cli script into a class.