Merge TLD code from Windows port, after cleanup