state diagram and examples added