The problem is being caused by insert invalidating some of the markers. So before adjusting the markers, we can check if the marker is valid or not. Following is a patch that does this.