improved clientUpgrade handler