fixed matrix to be in order