I still think it's more coherent to close the resource explicitly outside of this if.