hopefully fixed file handling