More fixes for bugs caused by mutable state. Hooray