cleaning up reduce sum implementation