refactor closeInstance to remove common dereference