Improve command line utility + refactoring