Merged fixes and improvements contributed by Ben Shadwick.
Updated documentation.