Fix a bug where the keyboard handler tries to delete non-existent Ace bindings and breaks all Ace bindings.
Re-order the handler code so that existing handlers are not removed until we have a valid replacement.