some refactoring and implementation