Added counting code