Documented Functions

Some updates to the code but mainly inline documentation additions to
document each of the functions etc.