Initial round of refactoring