Improve file closing, add filter