SDM: Code cleanup part 1: mean calculation