fixed small error with file not getting closed