upstream fixes and improvements