Refactorings needed for the scm-api branch.