Intramolecular reactions of N-acyliminium intermediates