Generalize cardinality estimator and tests
Minor cleanup