Add some api doc
Add tests
Try to DRY up some code