cleanup java api; add some tests