File handle leak fix