Minor refactoring, after failed attempt to introduce unittest.