You may need to call [sheet close] in addition to your [NSApp endSheet: sheet returnCode:23]
[sheet close]
[NSApp endSheet: sheet returnCode:23]