Fixed a bug with file operations being done twice, leading to erroneous behavior