Editor Script Handles.Label problem. Labels don't move with gameobject

I’m trying to create an editor script which lets me see the index of the vertices (of the gameObject’s mesh) to which the script is attached to. Here’s what I have so far.

using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(ModifyMesh))]
public class ModifyMeshEditor : Editor {
    
	GameObject theGO;
	MeshFilter mf;
	Mesh mesh;
	Vector3[] verts;

	void OnSceneGUI () {
		if (!Application.isPlaying) {
            theGO = Selection.activeGameObject;
			if (theGO != null) {
				mf = theGO.GetComponent<MeshFilter> ();
				mesh = mf.sharedMesh;
				verts = mesh.vertices;
			}
			Handles.color = Color.grey;
			for (int p = 0; p < verts.Length; p++) {
				Handles.Label (verts [p], p.ToString ());
			}
		}
	}
}

And the other class is this:

using UnityEngine;

[ExecuteInEditMode]
public class ModifyMesh : MonoBehaviour {

	GameObject g;

}

This works fine. There are however three problems: (could be more)

  1. When I move the gameobject in the scene view, the labels do not move along with it.

  2. A separate series of the same labels appears on an entirely different place in the same scene.

  3. There are multiple labels in the same position.

If you can shed some light on this topic and explain what is happening here and how to solve it, I’d be a happy man once again.

Thanks!

When you get the MeshFilter, you need to do something like Handles.matrix = mf.transform.localToWorldMatrix since all of those vertices are in the space of the object with the MeshFilter