complete the main function