Fix quality flaws and add test.