large refactoring to better seperate the responsibilities