improve file handling