counter overflow check
wiring change and bugs fixing