refactor with ipv6 support