cleanups and add running-average function
cleanups and add running-average function