Fixed a few bugs, reworked the api.