refactoring a big