Some more documentation and reordering of the functions