Fix crash when saving or canceling