Add `prepare` command and some refactoring