add keymaster
some refactorings