are you closing twice? (because of the defer)