cli: Fixed deinit ordering, misc error handling fixed.