Many misc fixes and improvements