Updated jacobian loop, fixed matrix sizes