massive code rewrite

..was required in order to unify the packet-generation code