refactor ipaddr gathering logic. #521