Made the API a lot more consistent, and added a lot of error checking around the code.