refactored the renderer code