working code, without udp