Several fixes and improvements.