Added sparse matrices + better termination criterion