Fixed crash when saving or canceling