Refactor port_range