Refactored the rendering code around to make it more streamlined.