Numerous fixes and changes