matrix to arrays refactor