traits and some refactoring