main function updated