fixed bug in counter wait function