Function now returns a list as the output instead of global variables. Need to write functions for plotting from the new lists