Added inital function bodies based on the mean example.
Tidied up the code, added comments. Functions tested and return data as expected.