merged refactorings from 4.17 branch