Added synchronized block to make the state class thread proof