Restructure bind_ports_helper() a bit