Modified to avoid thrust exception.