Implement generateFunction