rework tun code