Move measuretext out of main loop