DK|JP: Refactoring production and test code.