add tests and some changes to API