large refactor, added some new architecture