fix bug in main function