main function corrected