updating counter to account for edge cases