clean up code
nested sum