Handle of IOException and closing of input fixed.