Use pitch inversion for keyboard. Minor refactoring