Fix bug that Miles caught and fix tests.