Improve APIs, update tests