Corrections, added example.

Corrected some mistakes, improved error messages and added an example
demo.