Refactor Cli execution code