Changed some bits of code into created functions for emptying packets