Improved isProxyValidPort method