Bug fix in sum function.