Clean up the API a bit and add in some documentation.