refactoring
restructured, working