Major Comments added

This should make it easier to understand what i have done.
Also moved more functions to the functions library and reorganised it