Updating cleanup script with better SQL syntax