Improve CloseAllShells implementation