Total refactoring: subcommands to functions