added Messages class.
modified some logic of examples.