new structure and some refactoring