some refactoring and new functions
some refactoring and normalizing