replaced matrix with a 2D array