Fix dereference of freed delta

I was accidentally using a value that I had just freed.  This
moves the clearing of the delta internal flags into a better place.