Added some documentation comments.
Reordered some of the functions within the module so similar functions are grouped together.