Added counting and corresponding resetting function.