added count management logic