factored code into function
added data graphs