fixed counter overflow problem