Generating functions in two passes.