add some refactored code