refactor cli application and add tests