Rewrite slightly confusing try-finally