Update flatten.cpp