Added stat graph util spec, refactored code