refactor avahi code