fixed matrix bug