Refactored rendering portion of code