Merge pull request #565 from ejc123/FixMean

Need to handle count == 0 case.
Noticed wrong variable comparison when looking over code.