refactor the cli logic