Metal-catalyzed intramolecular C-N and C-O bond formation