Improved connection handling