Added a check for overwriting files.