Generalized genSource; finished sum handling (untested).