Updated main function.