Refactor 3d.js