Algorithm running, but there's a bug in the matrix