added detection of overflow in the counter