I had some cases in which this got called more than once, causing errors on the subsequent calls. This should fix that.