some refactor from MateUnity