Fix bugs, adjust API, rewrite the functional test API. Now passes the
wadereddi test.