This should avoid exceptions caused by existing files with different contents. I also removed some unused code.