fix TryClose function