messy refactoring