Fixed some bugs. Added a demo.