Improve handling of network and local connection