Refactor JavaScript renderer