Added sample averaging.