Rewrite of #18 to work with tests.