large refactor now more modular and complete