Fix linear algebra bug