Fixed bug for flatten