remove flatten and use Array.empty instead