fixed bugs, ready for udp implementation