Cleaned up the way file resources are closed to handle things cleanly