Fix spaces before parentheses.
Fix leak of socket_name and remove it from Windows builds.
Improve code clarity.
Properly detect and handle circular dependencies.
Factor system-independent code.
Document when functions are called.