Added code from tcp unit