improved connection management to be fork-safe