Misc refactoring, and fix DNS by changing strncpy implementation to be as expected (even though it now doesn't null-terminate)