Add missing tests, and fix a broken implementation.