moved insert outside transaction