second huge refactoring