fixed building gains, new bug by calculating DG, function computeDG.