fixed problem where i closed the file too soon