More tiny refactorings.
Merge upstream.