Further template refactoring for code and ipynb