fix bugs in Main