Changed stateFactory function.