build the first counting functions