separating socket logic