Whole lot of refactoring