Refactor rendering code a bit.