Minor refactorings and key binding code cleanup