fix GenerateMainFunction in DScript, and remove unused code