fix invalidCounter logic