since `text` got clobbered, it needed to be replaced with the original value. This could be refactored to not clobber `text`, and there may be a slight performance increase, but I think it would also be more complex code.