fix bug due to excessive mutable state