Refactored rendering code. did other things.