Pull sending packets out of the main function