Rewrote rendering code