Reorganize CLI code