Added unit tests, modified API a bit