Added state checking. Added example.