Add tests, fix bug.