Ensure that open files are closed to prevent resource leaks

Invoke close methods when done