serialize packets correctly