big ass refactoring