fixed a lot of bug