Fixed bug where internal state could get clobbered