Add tests and fix remaining errors.