Could all this "debug" code be moved to the tests?