more checks to make sure files get closed in Directory.java