Close files properly (RhBug: 1012290)