added def generate_function