Rewrite marker insertion algorithm.