fix bugs in SGen, still fixing bugs in the reduction tree version of the compute.py