Various bug fixes.