First bunch of refactoring changes