Various refactoring.