Cloned from the DNS script and slowly adjusting.