Add “list” subcommand and do some refactoring