Sundry bug fixes