main function complete