Merged edit and generation function