Various stability and refactorings into a better close file/files action