counter++ instead of ++ counter. It may fix the freezes