add proper file handling support