bug fix for main function