implemented state pattern