Moved graphite stats code to own function