Refactoring rendering code a bit