Compress the counterX variables into an array.

If only one of the if statements can be true, then
To get the code you've posted to execute faster, use if/else if vs all ifs. The first true if...