Improve file handling