fixed the api and added tests