Close files properly