minor optimizations to gui mainloop