First bunch of refactoring.