large refactor, make things more modular