Moved socket configuration to its own function