Reworked packet sending code