refining generate_impl