moved sum to scalar funcs