the main function all done, may be refine it later