added build.sh
refactored ReceivePackets
refactored ReceivePacket
refactored out repeated code