Improve tests, fix bugs.