Updated Analysis Function

Tidy code into functions.
Output tables as plots.