Changed API. Added tests and updated readme.