Move handlePacket out from the inner class