State machine kind of working