Some more refactoring to generators: nxt code separated into its lib