Minor refactoring
Merged conflicts from upstream