Fixed a bug where first file was getting wiped out