Refactored rendering code