Pull create_newfun into a separate function