setter function to set the state.