small refactor of rendering code