modified the example
Bugs fixed and tested