added error checking and added temporary file for removing with wildcards