refactoring structure and flow