Add unit tests, fix tests