Some refactoring of the CLI bits, added template preprocess