fix calculation for sparse