Optimized the redraw() function a bit.