merge refactoring upstream