organize main function