fix bugs in main