Numerous bug fixes.