Correctly close all handles