complete rewrite with subcommands