Shift bulk of calculations to average function and fix some logic errors.
Merge branch 'master' of github.com:webgeek1234/AWS_Zilog