Cleanup and add some convenience functions.