Cleaned up sum function