Various bug fixes, and modifications to examples.