Bug fix in Main()