Added syncronization to methods handling state.