added flatten copy