Drastically improved and finished averaging implementation, still need
tweaking, and there is a crashing bug