refactoring, put all nb generation into one function