finished implement array flatten