Refactoring to allow use of several renderers without using globals/switchTo + various cleanups