fix free_flatten_example
better flatten_example and free_flatten_example