Moved data processing for graph into it's own function, nice and dry.