cleaned/refactored sockets.c