Change the initial object to a function.
Add a top-level generate() convenience function.