some refactoring according to master