counts fitting function