Reworked the rendering code a bit