Tidy up rendering code