Tests and refactoring.