Improve test coverage and fix a bug.