use naive algorithm when nf < 5
cleanup