huge refactoring