add sum function to demo code