changing matrices to use arrays