Optimized background rendering code a bit