Better error checking.
Doc rewrite, lots of small improvements.