A lot of refactoring