Thermochemistry of carbene and nitrene rearrangements