Enhanced sparse matrix implementation