revised impl of build_packet()