Refactored for simplicity, plus adjustable time averaging for the graph