optimize cmd_exists