updated main function