changed indexing of matrix, which now minimizes error terms