improved api and added bunch of tests