New file structure and some refactoring