fix for properly closing connections using the wait group