started refactoring with factories, and more modularization