upstream imports and some related fixes