Lots of refactoring to make the API a little easier to work with