Refactor of convertToMatrix3d