Put the clock calls in more natural places at the beginning and end of mainloop, rather than outside of mainloop.