refactoring render.js