This allows canceling an in-progress render and moves some of the rendering code to a more appropriate location.