finish the main function