Another flatten implementation for arrays