Replaced jagged array with matrix