Added a check for existing files