improve code in socket article