First pass, untested.
Minor fixes and testing examples.