cleanup before save and export