some refactoring and more