Small refactorings and cleanup