cli: Refactoring and lock cleanup, part 1