Updated tests and minor refactoring.