finish the main function of the whole project