working version
calculating and returning the mean
minor tidying
part way complete