changed sum function