You really give yourself a hard time.
Don't you think it's finnaly time to check Kmotos Gravity Well code?
Just open the main.cpp of any Coin that have it (KDC, Vent, Mega) and study it. Just reading it will give you some good ideas I am sure. Also about how to do the averaging better/more correctly.