Various minor refactorings