Several bug fixes and changes.

See changelog for details.