First round of refactoring