Move functions out of generator.rs