State machine part 1.