fixed some file handle leak. additional ry-catch-finally check is required