Refactored the API slightly and added a few tests