added check for existing files in db