fix sparsity detection