Implementation of SetState