apply some refactoring