numerous fixes and improvements