State machine pattern added