faster flatten