fixed scope issue in sum