huge refactoring 2