fixed sum function--needs testing