Several minor refactorings