Cosmetic code change - Moved a sort function to a different location in the file and added some documentation
Added documentation for some functions