updated the main function