Refactor tests to use API. ref f2f19aec59d021f31d77106887044e923cd445c3