# Insertion vs epoxide formation

How can it be explained that in the first reaction mentioned below, a 7-membered ring dominates when the leaving group is nitrogen and an epoxide forms when the leaving group is dimethyl sulfide?

This is quoted from "The Art of Writing Reasonable Organic Reaction Mechanisms", Second Edition by Robert B. Grossman, DOI: 10.1007/b97257.

The $\ce{C}$ in diazomethane is nucleophilic. The product of attack of diazomethane on the carbonyl $\ce{C}$ has a leaving group a to the alkoxide, so either a 1,2 alkyl shift or direct nucleophilic displacement can occur. The insertion product happens to dominate with $\ce{H2\overset{-}{C}-\overset{+}{N}_2}$, but with $\ce{H2\overset{-}{C}-\overset{+}{S}Me2}$ the epoxide dominates.