normalization and some refactorings