Added counting funtion