Squashed commits: [a5217867f] (fix) ensure that ports are valid before trying to use them for setting the capability