refactor code of g3d