Tests and minor refactorings.