fixing error which stopped files being closed once opened.