Fixed lots of bugs. Added some example code