REFACTOR THREE.js injection code