Fixed file handling bugs.