added logic to check for existing files