fixed average calculation error