improved connection handling from riaken-core