Rewrote code close all open resources correctly after commit.