fixed a lot of bugs

fixed a lot of bugs