properly handle undefined ports