Modified GenerateSource() function