troubleshooting error with counter incrementing when it shouldn't