improved testing of sparse matrices and fixed error with opt version