update code, fix a lot of bug