Fix flatten that caused big NullPointerException.