fix mainloop counter