moving counting code to it own function on catagorical features