fixed bug in file handling