Refactoring for packets (probably broken)