Refactored THREE.js injection code