File handling fix