Factor out averaging function, do some rounding in step determination.