fix bugs with count boolean casting
fixes and optimizations for count feature
fix prepopulation count boolean bug
and very nice bug for the end! All tests now pass