Generalized the rendering code a bit