I already mentioned that I would make the killer someone else beside the jealous husband.
As for the ending, I would have Castle and Gina walk away. Castle yells over his shoulder for Beckett to have a good time at Demming's beach house. She tells him that she's not going. He stops and turns around. She looks away. He gets a little smirk. He tells her that his offer to his beach house is still open. She looks at him. A slight smile creeps up her lips. Then Gina, the mood killer, jumps in and says that Castle has no time to play. Camera pans back to Beckett who looks from Gina back to Castle. Then it fades as she opens her mouth. So we don't know what she says. OR. She turns him down but with a smile and a joke -- something like"I don't want to re-enact Naked Heatin the Hampton." Or something about the running gag ofhim trying to see her in a bathing suit and rubbing lotion on her back. And thentheysay goodbye to each other but they will see each other in the fall.
[No need for anyone to get hurt. Castle is not a soap opera. It's a comedy that has a dark undertone because they're investigating murders. They don't need to "hurt" the characters. But that's just my humble opinion.]
Ok, your turn to save the seasonfinale of Castle.